package _220315;

import java.util.Scanner;

/**
 * @author ShadowLim
 * @create 2022-03-15-12:31
 */
public class _缩位求和 {

    // 342ms
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        String n = scan.next();
        while (n.length() > 1) {
            int sum = 0;
            for (int i = 0; i < n.length(); i++) {
                // char to int
                sum += n.charAt(i) - '0'; // 或者：sum += Character.getNumericValue(n.charAt(i));
            }
            // int to string
            n = Integer.toString(sum);
        }
        System.out.println(n);
        scan.close();
    }
}
